package com.wyx.Common;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 元数据对象处理器
 */
@Component
public class Mymetaobjecthandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime", LocalDateTime.now());
//        System.out.println(Basecontext.getCurrendId());
        //这里使用到了threadLocal方法 将Id的值存入并提取
        //1.发送了一个添加或者修改的请求
        //2.LogincheckFilter判断了请求 是否包含employee 如果包含了就存到threadLocal变量区里面
        //3.get方法
        metaObject.setValue("updateUser", Basecontext.getCurrendId());
        metaObject.setValue("createUser", Basecontext.getCurrendId());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("updateTime", LocalDateTime.now());
        metaObject.setValue("updateUser", Basecontext.getCurrendId());
    }
}
